/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.ProductSpecEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class ProductSpecMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.selectAll
    
    public List<ProductSpecEntity> selectAll(String productTemplate, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_productspec where `productTemplate`='?' and `ytenant_id`=?;\n";
        parameter.addParam(productTemplate);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new ProductSpecEntity());
        return (List<ProductSpecEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(ProductSpecEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_productspec set `lsSpecItems_id` = ?, `code` = ?, `productId` = ?, `iSpecId` = ?, `specValue` = ?, `haveImg` = ?, `iSpecId_showItem` = ?, `iOrder` = ?, `productTemplate` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getLsSpecItems_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getiSpecId(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecValue(), Types.VARCHAR);
		parameter.addParamWithType(record.getHaveImg(), Types.BIT);
		parameter.addParamWithType(record.getiSpecId_showItem(), Types.VARCHAR);
		parameter.addParamWithType(record.getiOrder(), Types.INTEGER);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.insert
    
    public int insert(ProductSpecEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_productspec (`id`,`code`, `lsSpecItems_id`,  `productId`, `iSpecId`,  `specValue`, `haveImg`,  `iSpecId_showItem`, `iOrder`,  `productTemplate`, `ytenant_id`) values (?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.VARCHAR);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getLsSpecItems_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getiSpecId(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecValue(), Types.VARCHAR);
		parameter.addParamWithType(record.getHaveImg(), Types.BIT);
		parameter.addParamWithType(record.getiSpecId_showItem(), Types.VARCHAR);
		parameter.addParamWithType(record.getiOrder(), Types.INTEGER);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.insertBatch
    
    public Integer insertBatch(List<ProductSpecEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_productspec (`id`, `code`, `lsSpecItems_id`, `productId`, `iSpecId`, `specValue`, `haveImg`, `iSpecId_showItem`, `iOrder`, `productTemplate`, `ytenant_id`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				ProductSpecEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.VARCHAR);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getLsSpecItems_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductId(), Types.VARCHAR);
				parameter.addParamWithType(item.getiSpecId(), Types.VARCHAR);
				parameter.addParamWithType(item.getSpecValue(), Types.VARCHAR);
				parameter.addParamWithType(item.getHaveImg(), Types.BIT);
				parameter.addParamWithType(item.getiSpecId_showItem(), Types.VARCHAR);
				parameter.addParamWithType(item.getiOrder(), Types.INTEGER);
				parameter.addParamWithType(item.getProductTemplate(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE code=VALUES(code),iOrder=VALUES(iOrder),specValue=VALUES(specValue),iSpecId_showItem=VALUES(iSpecId_showItem),haveImg=VALUES(haveImg) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_productspec where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.selectById
    
    public ProductSpecEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_productspec where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new ProductSpecEntity());
        return (ProductSpecEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSpecMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_productspec where `id` = ?\n";
        parameter.addParamWithType(id, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

}
